package entity

import (
	"time"

	"shqsoft.cn/pasnj/base"

	"github.com/jinzhu/gorm"
)

//GDPHDR 国际结算量导入
type GDPHDR struct {
	ID   int       `gorm:"AUTO_INCREMENT;primary_key;column:JLID"`
	JJBH string    `gorm:"column:JJBH;"`
	ZJHM string    `gorm:"column:ZJHM;"`
	KHMC string    `gorm:"column:KHMC;"`
	ACBL float64   `gorm:"column:ACBL"`
	FFR  time.Time `gorm:"column:FFR"`
	DQR  time.Time `gorm:"column:DQR"`
	DRJG string    `gorm:"column:DRJG;"`
	DRRQ string    `gorm:"column:DRRQ;"`
}

//导入前执行分户处理
func gdphBeforeImport(tx *gorm.DB, params map[string]string) (err error) {
	prams := make([]interface{}, 1)
	prams[0] = params["DRRQ"]
	tx.Exec("DELETE FROM T_INDI_LOAN_PHJR WHERE LEFT(DRRQ,6)=LEFT(?,6) ", prams...)
	return nil
}

//xwphAfterImport 导入后执行
func gdphAfterImport(tx *gorm.DB, params map[string]string) (err error) {
	prams := make([]interface{}, 1)
	prams[0] = params["DRRQ"]
	err = tx.Exec("EXEC UP_INDI_LOAN_PHJR ?", prams...).Error
	if err != nil {
		return err
	}
	return nil
}

//TableName 国际中收导入表
func (GDPHDR) TableName() string {
	return "T_INDI_LOAN_PHJR"
}

//GDPHDREF 返回结构体
func GDPHDREF() base.EntityFunc {
	return func() interface{} {
		entity := GDPHDR{}
		return &entity
	}
}

//GDPHDRESF 返回结构体数组
func GDPHDRESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []GDPHDR
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("GDPHDR", base.NewDefaultDao(GDPHDREF(), GDPHDRESF(), nil))
	base.SetAfterCallBack("GDPHDR", gdphAfterImport)
	base.SetBeforeCallBack("GDPHDR", gdphBeforeImport)

}
